package com.etime.shuhuiyuan.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shuhuiyuan.dto.CourseAdminDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface CourseAdminDao extends BaseMapper<CourseAdminDto> {


    /**
     * 分页查询所有课程
     * @param page
     * @param courseAdminDto
     * @param coursetitle
     * @param coursestate
     * @param courseaudit
     * @return
     */
    @Select("<script> "+
            "SELECT c.courseid,c.coursetypeid,c.coursetitle,c.coursestate,c.courseaudit,c.courseauditdesc,c.coursepic,c.courseprice,c.courseoriginprice,c.coursecoinprice," +
            "c.coursecoinmaxpoint,c.coursecoinused,c.coursescore,c.coursepullcount,c.courserecommended,c.coursecommentcount," +
            "c.coursepaytype,c.coursesort,c.courseteachername,c.courseteacherid,c.courseorgid,o.orgname,o.orgid,ct.coursetypename " +
            "FROM course c LEFT JOIN organization o ON c.courseorgid=o.orgid " +
            "JOIN coursetype ct ON c.coursetypeid=ct.coursetypeid " +
            "<where> " +
            "<if test=' coursetitle != null and coursetitle != \"\" '> AND coursetitle LIKE #{coursetitle}</if> " +
            "<if test=' coursestate != null'> AND coursestate = #{coursestate}</if> " +
            "<if test=' courseaudit != null'> AND courseaudit = #{courseaudit}</if> " +
            "</where> " +
            "</script>")
    Page<CourseAdminDto> selectCourseByPage(Page<CourseAdminDto> page, CourseAdminDto courseAdminDto,@Param("coursetitle")String coursetitle,@Param("coursestate")Integer coursestate,@Param("courseaudit")Integer courseaudit);

    /**
     * 根据id查询单个课程
     * @param id
     * @return
     */
    @Select("SELECT c.courseid,c.coursetypeid,c.coursetitle,c.coursestate,c.courseaudit,c.courseauditdesc,c.coursepic,c.courseprice,c.courseoriginprice,c.coursecoinprice," +
            "c.coursecoinmaxpoint,c.coursecoinused,c.coursescore,c.coursepullcount,c.courserecommended,c.coursecommentcount," +
            "c.coursepaytype,c.coursesort,c.courseteachername,c.courseteacherid,c.courseorgid,o.orgname,o.orgid,ct.coursetypename,ct.coursetypeid " +
            "FROM course c LEFT JOIN organization o ON c.courseorgid=o.orgid " +
            "JOIN coursetype ct ON c.coursetypeid=ct.coursetypeid " +
            "WHERE c.courseid = #{id}")
    CourseAdminDto selectCourseAdminDtoById(@Param("id")Integer id);

}
